{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 文件操作\n",
    "from operator import *\n",
    "# 正则表达式\n",
    "import re\n",
    "# url解码用的\n",
    "import urllib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# 打开文件\n",
    "f = open('src/access_log_payload4.txt')\n",
    "# 正则\n",
    "lkp = re.compile(r'\\?.*?HTTP')\n",
    "# lkp =re.compile(r'HTTP')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "payloads = []\n",
    "# 依次匹配\n",
    "for line in f.readlines():\n",
    "#     print line\n",
    "#     print re.match(r'.*',line).groups()\n",
    "    group = lkp.findall(line)\n",
    "    if group:\n",
    "#         print group[0]\n",
    "        payloads.append(group[0]);\n",
    "\n",
    "# # 写入文件\n",
    "output = open('src/payload-use0.txt','w+')\n",
    "\n",
    "\n",
    "    \n",
    "# 修理payloads\n",
    "for pl in payloads:\n",
    "    pl = re.sub(r'\\?.*?\\=','',pl)\n",
    "    pl = re.sub(r' HTTP','',pl)\n",
    "    # url解码\n",
    "    pl = urllib.unquote(pl)\n",
    "    # 写入文件\n",
    "    output.write(pl)\n",
    "    output.write('\\n')\n",
    "# 关闭文件\n",
    "output.close()\n",
    "f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [Root]",
   "language": "python",
   "name": "Python [Root]"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
